﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace RentIt06WPFClient
{
    using RentIt06WPFClient.AdminSession;

    /// <summary>
    /// Interaction logic for ManageUsers.xaml
    /// </summary>
    public partial class ManageUser : Page
    {
        private AdminSession.Account account;
        public ManageUser(AdminSession.Account account) {
            InitializeComponent();
            this.account = account;
            this.updateView();
        }

        private void updateView() {
            foreach (var item in cbox.Items)
            {
                ((ComboBoxItem)item).FontWeight = FontWeights.Normal;
            }
            AccountGrid.DataContext = account;
            cbox.SelectedIndex = (int)account.Permission;
            ((ComboBoxItem)cbox.SelectedItem).FontWeight = FontWeights.Bold;
        }

        private void onDelete(object sender, RoutedEventArgs e)
        {
            Session.Admin.DeleteAccount(account.Id);
            NavigationService.GoBack();
        }

        private void onPromote(object sender, RoutedEventArgs e)
        {
            var perm = (PermissionGroup)cbox.SelectedIndex;
            Session.Admin.ChangeAccountAccessLevel(account.Id, perm);
            account.Permission = perm;
            this.updateView();
        }
    }
}
